package logic

import (
	"context"
	"gorm.io/gorm"
	"healthzy3/model/mysql"

	"healthzy3/healthzy3rpc/healthzy3rpc"
	"healthzy3/healthzy3rpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateLogic {
	return &UpdateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UpdateLogic) Update(in *healthzy3rpc.UpdateRequest) (*healthzy3rpc.UpdateResponse, error) {
	// todo: add your logic here and delete this line

	update := mysql.Health{
		Model:   gorm.Model{ID: uint(in.Id)},
		Name:    in.Name,
		Status:  in.Status,
		IdCard:  in.IdCard,
		Address: in.Address,
		Cater:   in.Cater,
		Type:    in.Type,
		Doctor:  in.Doctor,
		Price:   int(in.Price),
	}
	mysql.DB.Debug().Model(&update).Updates(&update)

	return &healthzy3rpc.UpdateResponse{Id: int64(update.ID)}, nil
}
